package com.heima.freemarker.controller;

import com.heima.freemarker.entity.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.servlet.ModelAndView;

import java.util.Map;

@Controller
public class HelloController {

    @GetMapping("/basic")
    public String test(Model model) {


        //1.纯文本形式的参数
        model.addAttribute("name", "freemarker");
        //2.实体类相关的参数

        Student student = new Student();
        student.setName("小明");
        student.setAge(18);
        model.addAttribute("stu", student);

        return "01-basic";
    }

    /**
     * 测试freemarker模板 model
     * @param model
     * @return
     */
    @GetMapping("/model")
    public String model(Model model) {
        model.addAttribute("name","你好,我是付山林");
        return "01-basic";
    }

    /**
     * 测试freemarker模板 modelMap
     * @param model
     * @return
     */
    @GetMapping("/modelMap")
    public String modelMap(ModelMap model) {
        model.addAttribute("name","你好,我是付山林");
        model.put("name","你好,我是章若楠");
        return "01-basic";
    }

    /**
     * 测试freemarker模板 modelAndView
     * @param
     * @return
     */
    @GetMapping("/modelAndView")
    public ModelAndView modelAndView() {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("name","你好,我是付山林");
        //挑转页面
        modelAndView.setViewName("01-basic");

        Student student = new Student();
        student.setName("小明");
        student.setAge(18);
        modelAndView.addObject("stu", student);
        return modelAndView;
    }
}